unit uFrmOrderDrink;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, DBCtrls, DB, OracleData, umainutils, ExtCtrls, GR32_Image;

type
  TFrmOrderDrink = class(TForm)
    btn_OrderDrink: TButton;
    OracleDataSetDrink: TOracleDataSet;
    DataSourceDrink: TDataSource;
    btn_Cancel: TButton;
    OracleDataSetType: TOracleDataSet;
    DataSourceType: TDataSource;
    edt_Price: TLabeledEdit;
    com_DrinkType: TDBLookupListBox;
    com_Drink: TDBLookupListBox;
    Image321: TImage32;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    procedure btn_CancelClick(Sender: TObject);
    procedure btn_OrderDrinkClick(Sender: TObject);
    procedure com_DrinkTypeClick(Sender: TObject);
    procedure com_DrinkClick(Sender: TObject);
  private
    { Private declarations }
    m_PlayerID, m_TableID, m_SeatNum, m_TicketID: string;
    procedure PopulateDrinkCombo();
    procedure PopulateDrinkTypeCombo();
  public
    { Public declarations }
    procedure ShowOrderDrinkForm(PlayerID, TableID, TicketID: string);
  end;

var
  FrmOrderDrink: TFrmOrderDrink;

implementation

uses uFrmMainLPT;
{$R *.dfm}

procedure TFrmOrderDrink.btn_OrderDrinkClick(Sender: TObject);
begin
  // get seat_num
  OraQueryMainUtils.Close;
  OraQueryMainUtils.SQL.Clear;
  if m_TicketID = '' then
    m_TicketID := '-1';
  OraQueryMainUtils.SQL.Text := ('SELECT SEAT_NUM FROM TICKETS WHERE ID=' + m_TicketID);
  OraQueryMainUtils.Execute;
  if not OraQueryMainUtils.Eof then
  begin
    m_SeatNum := OraQueryMainUtils.Field(0);
  end;
  InsertDataIntoDB('DRINK_ORDERS', 'DRINK_ID,TABLE_ID,PLAYER_ID,COMPLETED, DATETIME, SEAT_NUM', VarToStr(com_Drink.KeyValue) + ',' + '''' + m_TableID + '''' + ',' + '''' + m_PlayerID + '''' +
      ',''0'',(select sysdate from dual),' + '''' + m_SeatNum + '''');
  Close();
end;

procedure TFrmOrderDrink.com_DrinkClick(Sender: TObject);
begin
  if DataSourceDrink.DataSet.FieldValues['PRICE'] <> null then
    edt_Price.Text := DataSourceDrink.DataSet.FieldValues['PRICE'];
end;

procedure TFrmOrderDrink.com_DrinkTypeClick(Sender: TObject);
begin
  edt_Price.Text := '';
  PopulateDrinkCombo();
end;

procedure TFrmOrderDrink.btn_CancelClick(Sender: TObject);
begin
  Close();
end;

procedure TFrmOrderDrink.PopulateDrinkTypeCombo;
begin
  OracleDataSetType.CloseAll;
  OracleDataSetType.Session := OraSessMainUtils;
  OracleDataSetType.SQL.Clear;
  OracleDataSetType.SQL.Text := ('select * from DRINK_TYPES order by 1 DESC');
  // ---
  OracleDataSetType.Open;
  DataSourceType.DataSet := OracleDataSetType;
  com_DrinkType.ListSource := DataSourceType;
  com_DrinkType.KeyField := 'ID';
  com_DrinkType.ListField := 'NAME';
  com_DrinkType.KeyValue := null;
  com_Drink.KeyValue := null;
end;

procedure TFrmOrderDrink.PopulateDrinkCombo();
var
  WhereStr: string;
begin
  if com_DrinkType.KeyValue = null then
  begin
    WhereStr := '-1';
  end
  else
  begin
    WhereStr := VarToStr(com_DrinkType.KeyValue)
  end;
  OracleDataSetDrink.CloseAll;
  OracleDataSetDrink.Session := OraSessMainUtils;
  OracleDataSetDrink.SQL.Clear;
  OracleDataSetDrink.SQL.Text := ('select * from DRINKS where drink_type_id=' + WhereStr + ' order by 1 DESC');
  // ---
  OracleDataSetDrink.Open;
  DataSourceDrink.DataSet := OracleDataSetDrink;
  DataSourceDrink.DataSet.Filtered := false;
  com_Drink.ListSource := DataSourceDrink;
  com_Drink.KeyField := 'ID';
  com_Drink.ListField := 'NAME';
end;

procedure TFrmOrderDrink.ShowOrderDrinkForm(PlayerID, TableID, TicketID: string);
begin
  Label2.Caption := umainutils.Currency_Symbol;
  m_PlayerID := PlayerID;
  m_TableID := TableID;
  m_TicketID := TicketID;
  edt_Price.Text := '';
  PopulateDrinkTypeCombo();
  PopulateDrinkCombo();
  showmodal();
end;

end.
